home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / wpj1_8.zip / HOOKS.ZIP / SWATDLL.C < prev    next >
C/C++ Source or Header  |  1993-08-18  |  3KB  |  96 lines

  1. #define SWATDLL
  2. #include <windows.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "winswat.h"
  6.  
  7. static HHOOK hKhook = NULL;
  8. static HTASK hTASK = NULL;
  9. static HWND  hHWND = NULL;
  10. static HANDLE hInstance;
  11.  
  12. /* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
  13. /*                    Maint Entry Point For DLL                    */
  14. /* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
  15. int WINAPI LibMain (HMODULE hModule, WORD wDataSeg, WORD wHeapSize,
  16.                     LPSTR lpszCmdLine)
  17.    {
  18.    hInstance = hModule;
  19.  
  20.    if (wHeapSize > 0)
  21.       UnlockData (0);
  22.  
  23.    return 1;
  24.    }
  25.  
  26. /* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
  27. /*                     DLL Termination Routine                     */
  28. /* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
  29. int WINAPI WEP (int nParam)
  30.    {
  31.    return 1;
  32.    }
  33.  
  34. /* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
  35. /*                     Debug Output With Parms                     */
  36. /* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
  37. void VarDebug(char *szFormat, ...)
  38.    {
  39.    static char szBuffer[256];
  40.    static char far *pArguments;
  41.  
  42.    pArguments = (char *) &szFormat + sizeof szFormat;
  43.    wvsprintf(szBuffer, szFormat, pArguments);
  44.    OutputDebugString((LPSTR)szBuffer);
  45.    }
  46.  
  47. /* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
  48. /*                   Install Windows SHELL Hook                    */
  49. /* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
  50. void WINAPI _export InitialiseSwat(BOOL fAction, HWND hwnd)
  51.    {
  52.    if (fAction)
  53.       {
  54.       OutputDebugString("SWATDLL: Pre--SetHook\n");
  55.       hKhook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) KeyboardHook,
  56.                                 hInstance, NULL);
  57.       OutputDebugString("SWATDLL: Post-SetHook\n");
  58.       hTASK = GetWindowTask(hwnd);
  59.       hHWND = hwnd;
  60.       }
  61.    else
  62.       {
  63.       UnhookWindowsHookEx(hKhook);
  64.       hKhook  = NULL;
  65.       hHWND = NULL;
  66.       hTASK = NULL;
  67.       }
  68.    }
  69.  
  70. /* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
  71. /*                          Keyboard Hook                          */
  72. /* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
  73. DWORD CALLBACK KeyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
  74.    {
  75.    static BOOL fPost;
  76.    BYTE iBit;
  77.    WORD iWord;
  78.    static UINT iQky = 83;
  79.  
  80.    if (nCode >= 0)
  81.       if (wParam == iQky)
  82.          {
  83.          OutputDebugString("SWATDLL: Key Hook Hit\n");
  84.          iWord = HIWORD(lParam);
  85.          iBit  = HIBYTE(iWord);
  86.          if (iBit & 0x20)
  87.             {
  88.             fPost = PostMessage(hHWND, WM_COMMAND, WAKESIGL, 0);
  89.             return 1;
  90.             }
  91.          }
  92.  
  93.    CallNextHookEx(hKhook, nCode, wParam, lParam);
  94.    return 0;
  95.    }
  96.